package com.xsmart.order.services;

import com.baomidou.mybatisplus.plugins.Page;
import com.xsmart.common.constant.ResultConstant;
import com.xsmart.common.entity.RequestBean;
import com.xsmart.common.entity.ResponseBean;
import com.xsmart.order.dao.AdConfigruationDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author DIYC
 */
@Service
public class AdConfigruationService {
    @Autowired
    AdConfigruationDao adConfigruationDao;

    /**
     * 分页查询
     * @param requestBean
     * @return
     */
    public ResponseBean queryAdConfigruation(RequestBean requestBean){
        int currentPage = requestBean.getRequestParamInteger("currentPage", 1);
        int pageSize = requestBean.getRequestParamInteger("pageSize", 10);
        String seatCode = requestBean.getRequestParamString("seat_code");
        Integer seatType = requestBean.getRequestParamInteger("seat_type");
        Map<String, Object> map = new HashMap<>();
        map.put("seat_code", seatCode);
        map.put("seat_type", seatType);
        Page<Map<String, Object>> page = new Page<>(currentPage, pageSize);
        page.setRecords(adConfigruationDao.queryAdConfigruation(page, map));
        ResponseBean responseBean = requestBean.getResponseBean();
        responseBean.addResultPageItem("adConfigruationList", page);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }

    /**
     * 新增广告位置配置
     * @param requestBean
     * @return
     */
    public ResponseBean addAdConfigruation(RequestBean requestBean){
        ResponseBean responseBean = requestBean.getResponseBean();
        String seatCode = requestBean.getRequestParamString("seat_code");
        String seatName = requestBean.getRequestParamString("seat_name");
        Integer seatType = requestBean.getRequestParamInteger("seat_type");
        Map<String, Object> map = new HashMap<>();
        map.put("seat_code", seatCode);
        map.put("seat_name", seatName);
        map.put("seat_type", seatType);
        int num = adConfigruationDao.addAdConfigruation(map);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }

    /**
     * update
     * @param requestBean
     * @return
     */
    public ResponseBean modAdConfigruation(RequestBean requestBean){
        ResponseBean responseBean = requestBean.getResponseBean();
        Integer seatId = requestBean.getRequestParamInteger("seat_id");
        String seatCode = requestBean.getRequestParamString("seat_code");
        String seatName = requestBean.getRequestParamString("seat_name");
        Integer seatType = requestBean.getRequestParamInteger("seat_type");
        Map<String, Object> map = new HashMap<>();
        map.put("seat_code", seatCode);
        map.put("seat_name", seatName);
        map.put("seat_type", seatType);
        map.put("seat_id", seatId);
        int num = adConfigruationDao.modAdConfigruation(map);
        responseBean.setResult(ResultConstant.SUCCESS);
        return  responseBean;
    }

    /**
     * 删除
     * @param requestBean
     * @return
     */
    public ResponseBean delAdConfigruation(RequestBean requestBean){
        ResponseBean responseBean = requestBean.getResponseBean();
        Integer seatId = requestBean.getRequestParamInteger("seat_id");
        int num = adConfigruationDao.delAdConfigruation(seatId);
        return responseBean;
    }

    /**
     * 查询全部的广告推荐位置列表
     * @param requestBean
     * @return
     */
    public ResponseBean queryAllAdConfigruation(RequestBean requestBean){
        ResponseBean responseBean = requestBean.getResponseBean();
        List<Map<String, Object>> adConfigruationList = adConfigruationDao.queryAllAdConfigruation();
        responseBean.addResultItem("adConfigruationList", adConfigruationList);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }
}
